﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GEA
{
    public partial class frmLogin : Form
    {
        clDatabase dbOp = new clDatabase();
        int Result = -1;

        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            //Result = dbOp.GetID("select id from tbUtilizadores where Utilizador='" + txtUser.Text + "' and Senha='" + txtPass.Text + "'");
            Utilizador Ut = new Utilizador();
   

            Ut = dbOp.Get_Utilizador(txtUser.Text, txtPass.Text);
            GlobalVar.GlobalValue = Ut.IdUtilizador;
            Result = Ut.IdNivel;

            if (Result != 0)
            {
                //TODO: Armazenar IDNivel

                this.Close();
            }
            else
            {
                MessageBox.Show("Utilizador/Senha inexistentes!", "InGest: Erro no acesso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            //this.Close();
        }

        private void btnLogOut_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            ActiveControl = txtUser;
            //lblTitulo.Text = lblTitulo.Text + " (v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + ")";

            if (!CheckHD.HDSerial.CheckSerial())
            {

                label1.Visible = false;
                label2.Visible = false;
                txtUser.Visible = false;
                txtPass.Visible = false;

                btnLogin.Visible = false;

                label3.Visible = true;

            }


        }

        private void frmLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            //MessageBox.Show(GlobalVar.GlobalValue.ToString());
            //if (Result == -1)
            //{
            //    frmEntreposto jEntreposto = new frmEntreposto();
            //    jEntreposto.MdiParent = this.ParentForm;
            //    jEntreposto.Dock = DockStyle.Fill;
            //    jEntreposto.Show();
            //    Application.Exit();
            //}
        }
    }
}
